package com.example.module_patrol.ui.PatrolNotDoingDetail

import android.os.Bundle
import android.widget.ImageView
import androidx.activity.enableEdgeToEdge
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.example.lib_common.base.BaseActivity
import com.example.lib_common.utils.ToastUtils
import com.example.module_patrol.R
import com.example.module_patrol.adapter.NotDoingDetailAdapter
import com.example.module_patrol.adapter.PatrolAdapter
import com.example.module_patrol.databinding.ActivityNotDoingDetailBinding
import com.example.module_patrol.model.PatrolEntity
import com.example.module_patrol.model.PatrolNotDoingEntity
import com.example.module_patrol.ui.PatrolViewmodel
import com.google.gson.Gson
import dagger.hilt.android.AndroidEntryPoint
@Route(path = "/patrol/NotDoingDetailActivity")
@AndroidEntryPoint
class NotDoingDetailActivity : BaseActivity<PatrolViewmodel,ActivityNotDoingDetailBinding>() {
    @Autowired(name = "entity")
    @JvmField
    var entity: String? = null
    override val mLayoutResId: Int
        get() = R.layout.activity_not_doing_detail
    private val mViewModel: PatrolViewmodel by viewModels()
    lateinit var pkAdapter: NotDoingDetailAdapter
    private lateinit var patrolEntity: PatrolNotDoingEntity
    private var back: ImageView? = null

    override fun initView() {
        // 在此处解析JSON，确保ARouter已注入entityJson
        patrolEntity = Gson().fromJson(entity, PatrolNotDoingEntity::class.java) ?: run {
            ToastUtils.showLong(this, "数据传递错误")
            finish()
            return
        }
        /*
       返回键
        */
        back=mBinding.topBar5.findViewById(R.id.back)
        back!!.setOnClickListener {
            finish()
        }

        pkAdapter = NotDoingDetailAdapter()
        mBinding.rv.adapter = pkAdapter
        mBinding.rv.layoutManager = LinearLayoutManager(this)

        patrolEntity.patrolPoints.forEach {
             mViewModel.getPatrolById(it)
        }
        mBinding.time.text = patrolEntity.patrolTime
//巡检状态（0-未巡检、1-巡检中、2-已完成、3-已作废）
        when(patrolEntity.patrolStatus){
            "0"->{
                mBinding.type2.text = "未巡检"
//                mBinding.type2.setTextColor(resources.getColor(R.color.red))
            }
            "1"->{
                mBinding.type2.text = "巡检中"
//                mBinding.type2.setTextColor(resources.getColor(R.color.green))
            }
            "2"->{
                mBinding.type2.text = "已完成"
//                mBinding.type2.setTextColor(resources.getColor(R.color.gray))
            }
            "3"->{
                mBinding.type2.text = "已作废"
//                mBinding.type2.setTextColor(resources.getColor(R.color.gray))
            }
        }
    }

    override fun initData() {
        mViewModel.getPatrolByIdLiveData.observe(this){
            if (it==null){
                return@observe
            }
            pkAdapter.addPatrol(it)
        }
    }

}